package com.homestay.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.homestay.service.GetMessageCode;
import com.homestay.tools.SendEmailtool;

@Controller
public class SendEmail {
	/**
	 * 通过邮箱登录
	 * @param req
	 * @param resp
	 */
	@RequestMapping("/sendEmail.action")
	public void SendEmail(HttpServletRequest req, HttpServletResponse resp){
		String email=req.getParameter("email");
		System.out.println(email);
		//根据获取到的邮箱号发送验证码
		String code=GetMessageCode.smsCode(); 
		System.out.println(code);
		try {
			//将后台生成的验证码传到前台
			resp.getWriter().print(code);
			SendEmailtool.send(email, "凡舍", code);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
